package com.eightbears.beboy.ui.user.activity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.PoiItem;
import com.amap.api.services.core.SuggestionCity;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeAddress;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.amap.api.services.help.Inputtips;
import com.amap.api.services.help.InputtipsQuery;
import com.amap.api.services.help.Tip;
import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.eightbears.beboy.R;
import com.eightbears.beboy.adapter.LocationAddressAdapter;
import com.eightbears.beboy.base.BaseActivity;
import com.eightbears.beboy.base.util.AMapUtil;
import com.eightbears.beboy.base.util.ShowToast;
import com.eightbears.beboy.base.view.SwipeBackLayout;
import com.eightbears.beboy.base.view.layout.MyLinearLayoutManager;
import com.socks.library.KLog;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @创建者 Administrator
 * @创建时间 Created by Administrator on 2017/5/15.
 * @描述 选择位置页面
 * @更新 $Author$
 * @更新时间 2017/5/15
 * @更新描述 ${TODO}.
 */

public class ShowLocationActivity extends BaseActivity implements TextWatcher, Inputtips.InputtipsListener,
        BaseQuickAdapter.RequestLoadMoreListener, SwipeRefreshLayout.OnRefreshListener, PoiSearch.OnPoiSearchListener,
        AMap.OnCameraChangeListener, LocationSource, AMapLocationListener, View.OnClickListener, GeocodeSearch.OnGeocodeSearchListener {

    public static final String PARAMS_LATITUDE = "Latitude";
    public static final String PARAMS_LONGITUDE = "Longitude";
    public static final String PARAMS_ADDRESS = "address";
    public static final String PARAMS_PROVINCE = "province";
    public static final String PARAMS_DISTRICT = "district";
    public static final String PARAMS_CITY = "city";

    //显示地图需要的变量//地图控件
    @BindView(R.id.map_marker_fixed)
    TextureMapView mapView;
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.ll_back)
    LinearLayout ll_back;

    private AMap aMap;//地图对象
    private LocationSource.OnLocationChangedListener mListener = null;//定位监听器
    //标识，用于判断是否只显示一次定位信息和用户重新定位
    private boolean isFirstLoc = true;
    private TextView mTv_save_address;
    private LinearLayout mLl_back;
    private BitmapDescriptor movingDescriptor;
    private BitmapDescriptor chooseDescripter;
    private ValueAnimator animator = null;
    private GeocodeSearch geocodeSearch;
    private LatLng myLocation;
    private Handler handler = new Handler();
    private ArrayList<PoiItem> addresslist = new ArrayList();//存放地址地址

    private AMapLocationClient mlocationClient;

    private PoiSearch.Query query;// Poi查询条件类

    private RecyclerView mRv_setcomment_list;
    private LocationAddressAdapter mLocationAddressAdapter;
    //    private TextView               mTv_selection_location_top;
    private LatLonPoint mPoint;
    private String mLatitude;
    private String mLongitude;
    private String mAddress;
    String province;
    String city;
    String district;
    private AutoCompleteTextView mEt_location_query;
    private List<Tip> listInput;
    private SwipeBackLayout swipeBackLayoutTwo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_selection_location);
        ButterKnife.bind(this);
        //初始化地图
        initMap();
        setUpLocationStyle();
        mapView.onCreate(savedInstanceState);
        initView();
        initData();
        initEvent();
    }

    /**
     * 初始化高德地图  //TODO
     */
    private void initMap() {
        // 初始化地图变量
        if (aMap == null) {
            aMap = mapView.getMap();
        }
        //设置显示定位按钮 并且可以点击
        UiSettings settings = aMap.getUiSettings();
        //设置定位监听
        aMap.setLocationSource(this);
        // 是否显示定位按钮
        settings.setMyLocationButtonEnabled(true);
        // 是否可触发定位并显示定位层
        aMap.setMyLocationEnabled(true);
        //设置缩放级别
        aMap.moveCamera(CameraUpdateFactory.zoomTo(15));
        //图
        movingDescriptor = BitmapDescriptorFactory
                .fromResource(R.mipmap.location_moving);
        chooseDescripter = BitmapDescriptorFactory
                .fromResource(R.mipmap.location_moving);
        BitmapDescriptor successDescripter = BitmapDescriptorFactory
                .fromResource(R.mipmap.location_moving);
        //编码
        geocodeSearch = new GeocodeSearch(this);
        geocodeSearch.setOnGeocodeSearchListener(this);
    }

    private void setUpLocationStyle() {
        // 自定义系统定位蓝点
        MyLocationStyle myLocationStyle = new MyLocationStyle();
        myLocationStyle.myLocationIcon(BitmapDescriptorFactory
                .fromResource(R.mipmap.icon_gps));
        myLocationStyle.strokeWidth(1);
        myLocationStyle.radiusFillColor(Color.TRANSPARENT);
        aMap.setMyLocationStyle(myLocationStyle);
    }

    @Override
    protected void initView() {

        //侧滑删除实力化
        swipeBackLayoutTwo = (SwipeBackLayout) findViewById(R.id.sw_shopdetail);

        mEt_location_query = (AutoCompleteTextView) findViewById(R.id.et_search);
        mRv_setcomment_list = (RecyclerView) findViewById(R.id.rv_setcomment_list);
//        mTv_selection_location_top = (TextView) findViewById(R.id.tv_selection_location_top);
        SwipeRefreshLayout swipeLayout_setcomment = (SwipeRefreshLayout) findViewById(R.id.swipeLayout_setcomment);
        swipeLayout_setcomment.setOnRefreshListener(this);
        swipeLayout_setcomment.setColorSchemeColors(getResources().getColor(R.color.text_color_ccc),
                getResources().getColor(R.color.text_color_ccc),
                getResources().getColor(R.color.text_color_ccc),
                getResources().getColor(R.color.text_color_ccc));

        mRv_setcomment_list.setLayoutManager(new MyLinearLayoutManager(this));
        mTv_save_address = (TextView) findViewById(R.id.tv_save_address);
        mLl_back = (LinearLayout) findViewById(R.id.ll_back);
        mTv_save_address.setVisibility(View.VISIBLE);
        mTv_save_address.setText("完成");
        tv_title.setText("选择位置");
    }

    @Override
    protected void initData() {
        mLocationAddressAdapter = new LocationAddressAdapter();
        mLocationAddressAdapter.openLoadAnimation();
//        mLocationAddressAdapter.setOnLoadMoreListener(this);
        mRv_setcomment_list.setAdapter(mLocationAddressAdapter);
    }

    @Override
    protected void initEvent() {
        swipeBackLayoutTwo.setCallBack(new SwipeBackLayout.CallBack() {
            @Override
            public void onFinish() {
                finish();
            }
        });

        mRv_setcomment_list.addOnItemTouchListener(new OnItemChildClickListener() {
            @Override
            public void onSimpleItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                PoiItem poiItem = addresslist.get(position);
                aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(poiItem.getLatLonPoint().getLatitude(), poiItem.getLatLonPoint().getLongitude())));
                //用作设置返回地址数据到上一个页面
                mLatitude = poiItem.getLatLonPoint().getLatitude() + "";
                mLongitude = poiItem.getLatLonPoint().getLongitude() + "";
                mAddress = poiItem.getTitle();
                province = poiItem.getProvinceName();
                city = poiItem.getCityName();
                district = poiItem.getAdName();
                //数据是使用Intent返回
                Intent intent = new Intent();
                //把返回数据存入Intent
                intent.putExtra(PARAMS_LATITUDE, mLatitude);
                intent.putExtra(PARAMS_LONGITUDE, mLongitude);
                intent.putExtra(PARAMS_ADDRESS, mAddress);
                intent.putExtra(PARAMS_PROVINCE, province);
                intent.putExtra(PARAMS_CITY, city);
                intent.putExtra(PARAMS_DISTRICT, district);
                //设置返回数据
                setResult(RESULT_OK, intent);
            }
        });

        mTv_save_address.setOnClickListener(this);
        mLl_back.setOnClickListener(this);
        mEt_location_query.addTextChangedListener(this);

        mEt_location_query.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //关闭软键盘
                InputMethodManager imm = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mEt_location_query.getWindowToken(), 0);

                KLog.e(mEt_location_query.getText().toString().trim());//TODO

                //获取point
                LatLonPoint point = listInput.get(position).getPoint();
                //中心点移动到当前point点坐标的位置
                aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(point.getLatitude(), point.getLongitude())));
                //查询
                doSearchQuery(point);
                //用作设置返回地址数据到上一个页面
                mLatitude = point.getLatitude() + "";
                mLongitude = point.getLongitude() + "";
                mAddress = listInput.get(position).getDistrict() + listInput.get(position).getName();

                //数据是使用Intent返回
                Intent intent = new Intent();
                //把返回数据存入Intent
                intent.putExtra(PARAMS_LATITUDE, mLatitude);
                intent.putExtra(PARAMS_LONGITUDE, mLongitude);
                intent.putExtra(PARAMS_ADDRESS, mAddress);
                intent.putExtra(PARAMS_PROVINCE, province);
                intent.putExtra(PARAMS_CITY, city);
                intent.putExtra(PARAMS_DISTRICT, district);
                //设置返回数据
                setResult(RESULT_OK, intent);
            }
        });
    }

    //定位回调函数
    @Override
    public void onLocationChanged(AMapLocation amapLocation) {
        if (amapLocation != null) {
            if (amapLocation.getErrorCode() == 0) {
                //定位成功回调信息，设置相关消息
                amapLocation.getLocationType();//获取当前定位结果来源，如网络定位结果，详见官方定位类型表
                amapLocation.getAccuracy();//获取精度信息
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = new Date(amapLocation.getTime());
                df.format(date);//定位时间

                amapLocation.getAddress();//地址，如果option中设置isNeedAddress为false，则没有此结果，网络定位结果中会有地址信息，GPS定位不返回地址信息。
                amapLocation.getCountry();//国家信息
                province = amapLocation.getProvince();//省信息
                city = amapLocation.getCity();//城市信息
                district = amapLocation.getDistrict();//城区信息
                amapLocation.getStreet();//街道信息
                amapLocation.getStreetNum();//街道门牌号信息
                amapLocation.getCityCode();//城市编码
                amapLocation.getAdCode();//地区编码

                // 如果不设置标志位，此时再拖动地图时，它会不断将地图移动到当前的位置
                if (mListener != null) {
                    //将地图移动到定位点
                    LatLng latLngLocation = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude());
                    aMap.moveCamera(CameraUpdateFactory.changeLatLng(latLngLocation));
                    mListener.onLocationChanged(amapLocation);//显示系统小蓝点
                    aMap.moveCamera(CameraUpdateFactory.zoomTo(15));

                    //启动周边搜索
                    mPoint = new LatLonPoint(amapLocation.getLatitude(),
                            amapLocation.getLongitude());
                    RegeocodeQuery query = new RegeocodeQuery(mPoint, 5000, GeocodeSearch.AMAP);
                    //查询
                    geocodeSearch.getFromLocationAsyn(query);
                    if (centerMarker != null) {
                        animMarker();
                    }
                    doSearchQuery(mPoint);

                    //获取地址信息
                    mAddress = (amapLocation.getProvince() + "" + amapLocation.getCity() + "" + amapLocation.getDistrict() + "" + amapLocation.getStreet() + "" + amapLocation.getStreetNum());
                    //新建poiItem
                    PoiItem poiItem = new PoiItem("", mPoint, mAddress, "");
                    //添加到集合用来存放PoiItem用作列表显示
                    addresslist.add(0, poiItem);

//                    //设置当前位置
//                    mTv_selection_location_top.setText(mAddress);
//                   T.getInstance().Short(mAddress.toString());

                    KLog.e("获取位置" + mAddress.toString());
                    //网络获取数据XXXXXXXXX
                    mLatitude = amapLocation.getLatitude() + "";
                    mLongitude = amapLocation.getLongitude() + "";

                    //创建坐标
                    myLocation = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude());
                    //传递定位坐标和具体位置参数
//                    startLocalActivity(mContext,);
                    //固定大头针
                    fixedMarker();
                }
            } else {
                //显示错误信息ErrCode是错误码，errInfo是错误信息，详见错误码表。
                Log.e("AmapError", "location Error, ErrCode:" + amapLocation.getErrorCode() + ", errInfo:" + amapLocation.getErrorInfo());
                ShowToast.showLongToast("定位失败");
            }
        }
    }


    /**
     * 激活定位
     */
    @Override
    public void activate(OnLocationChangedListener listener) {
        mListener = listener;
        if (mlocationClient == null) {
            mlocationClient = new AMapLocationClient(this);
            AMapLocationClientOption locationOption = new AMapLocationClientOption();
            //设置定位监听
            mlocationClient.setLocationListener(this);
            //设置为高精度定位模式

            //设置是否返回地址信息（默认返回地址信息）
            locationOption.setNeedAddress(true);
            //设置是否只定位一次,默认为false
            locationOption.setOnceLocation(true);
            //设置是否强制刷新WIFI，默认为强制刷新
            locationOption.setWifiActiveScan(true);
            //设置是否允许模拟位置,默认为false，不允许模拟位置
            locationOption.setMockEnable(false);
//        mLocationOption.setInterval(2000);
            //设置定位模式为高精度模式，Battery_Saving为低功耗模式，Device_Sensors是仅设备模式
            locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
            //设置定位参数
            mlocationClient.setLocationOption(locationOption);
            // 此方法为每隔固定时间会发起一次定位请求，为了减少电量消耗或网络流量消耗，
            // 注意设置合适的定位时间的间隔（最小间隔支持为2000ms），并且在合适时间调用stopLocation()方法来取消定位请求
            // 在定位结束后，在合适的生命周期调用onDestroy()方法
            // 在单次定位情况下，定位无论成功与否，都无需调用stopLocation()方法移除请求，定位sdk内部会移除
            mlocationClient.startLocation();
        }
    }

    /**
     * 方法必须重写
     * map的生命周期方法
     */
    @Override
    public void onResume() {
        mapView.setVisibility(View.VISIBLE);
        mapView.onResume();
        super.onResume();
    }

    /**
     * 方法必须重写
     * map的生命周期方法
     */
    @Override
    public void onPause() {
        mapView.setVisibility(View.GONE);
        mapView.onPause();
        super.onPause();
    }


    /**
     * 方法必须重写
     * map的生命周期方法
     */
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    /**
     * 方法必须重写
     * map的生命周期方法
     */
    @Override
    public void onDestroy() {
        mapView.setVisibility(View.GONE);
        mapView.onDestroy();
        destroyLocation();
        super.onDestroy();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_save_address:
                //数据是使用Intent返回
                Intent intent = new Intent();
                //把返回数据存入Intent
                intent.putExtra(PARAMS_LATITUDE, mLatitude);
                intent.putExtra(PARAMS_LONGITUDE, mLongitude);
                intent.putExtra(PARAMS_ADDRESS, mAddress);
                intent.putExtra(PARAMS_PROVINCE, province);
                intent.putExtra(PARAMS_CITY, city);
                intent.putExtra(PARAMS_DISTRICT, district);
                //设置返回数据
                setResult(RESULT_OK, intent);
                finish();
                break;
            case R.id.ll_back:
                //数据是使用Intent返回
                finish();
                break;
        }
    }

    @SuppressLint("NewApi")
    private void endAnim() {
        if (animator != null && animator.isRunning())
            animator.end();
    }

    @Override
    public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
        KLog.e("到这里1" + "i== " + i);
        if (i == 1000) {
            if (regeocodeResult != null
                    && regeocodeResult.getRegeocodeAddress() != null) {
                endAnim();
                centerMarker.setIcon(chooseDescripter);
                RegeocodeAddress regeocodeAddress = regeocodeResult.getRegeocodeAddress();
                String formatAddress = regeocodeResult.getRegeocodeAddress()
                        .getFormatAddress();
                KLog.e("地址 " + formatAddress);
                //TODO
                //获取当前位置
                String shortAdd = formatAddress
                        .replace(regeocodeAddress.getProvince(), "")
                        .replace(regeocodeAddress.getCity(), "")
                        .replace(regeocodeAddress.getDistrict(), "");
//                T.getInstance().CenterShort(formatAddress);
//                showPopupWindow(shortAdd);
            } else {

            }
        } else {

        }
    }

    @Override
    public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {

    }

    private Marker centerMarker;

    /**
     * 固定大头针
     */
    private void fixedMarker() {
        MarkerOptions centerMarkerOption = new MarkerOptions().position(
                myLocation).icon(chooseDescripter);
        centerMarker = aMap.addMarker(centerMarkerOption);
        centerMarker.setPositionByPixels(mapView.getWidth() / 2,
                mapView.getHeight() / 2);
        //主线称
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                CameraUpdate update = CameraUpdateFactory.zoomTo(17);
                aMap.animateCamera(update, 1000, new AMap.CancelableCallback() {
                    @Override
                    public void onFinish() {
                        aMap.setOnCameraChangeListener((AMap.OnCameraChangeListener) mContext);
                    }

                    @Override
                    public void onCancel() {
                    }
                });
            }
        }, 1000);
    }

    private boolean isMovingMarker = false;

    /**
     * 移动时大头针的ICON
     */
    private void setMovingMarker() {
        if (isMovingMarker)
            return;
        isMovingMarker = true;
        centerMarker.setIcon(movingDescriptor);
    }

    @Override
    public void onCameraChange(CameraPosition cameraPosition) {
        if (centerMarker != null) {
            //设置移动时大头针的ICON
            setMovingMarker();
        }
    }


    @Override
    public void onCameraChangeFinish(CameraPosition cameraPosition) {
        KLog.e("onCameraChangeFinish1");
        //获取当前屏幕中心坐标
        mPoint = new LatLonPoint(cameraPosition.target.latitude,
                cameraPosition.target.longitude);
        RegeocodeQuery query = new RegeocodeQuery(mPoint, 5000, GeocodeSearch.AMAP);
        //查询
        geocodeSearch.getFromLocationAsyn(query);
        if (centerMarker != null) {
            KLog.e("onCameraChangeFinish2");
            animMarker();
        }
        doSearchQuery(mPoint);
    }

    @SuppressLint("NewApi")
    private void animMarker() {
        isMovingMarker = false;
        if (animator != null) {
            animator.start();
            return;
        }
        animator = ValueAnimator.ofFloat(mapView.getHeight() / 2,
                mapView.getHeight() / 2 + 50);
        animator.setInterpolator(new DecelerateInterpolator());
        animator.setDuration(300);
        animator.setRepeatCount(1);
        animator.setRepeatMode(ValueAnimator.REVERSE);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                Float value = (Float) animation.getAnimatedValue();
                centerMarker.setPositionByPixels(mapView.getWidth() / 2,
                        Math.round(value));
            }
        });
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                centerMarker.setIcon(chooseDescripter);
            }
        });
        animator.start();
    }

    /**
     * 停止定位
     */
    @Override
    public void deactivate() {
        mListener = null;
        if (mlocationClient != null) {
            mlocationClient.stopLocation();
            mlocationClient.onDestroy();
        }
        mlocationClient = null;
    }

    /**
     * 开始进行poi搜索
     */
    protected void doSearchQuery(LatLonPoint point) {
        int currentPage = 0;
        String keyWord = "风景名胜|商务住宅|政府机构及社会团体|交通设施服务|公司企业|道路附属设施|地名地址信息";
        query = new PoiSearch.Query(keyWord, "", city);// 第一个参数表示搜索字符串，第二个参数表示poi搜索类型，第三个参数表示poi搜索区域（空字符串代表全国）
        //        SearchBound searchBound = new SearchBound(lp, 5000);

        query.setPageSize(20);// 设置每页最多返回多少条poiitem
        query.setPageNum(currentPage);// 设置查第一页

        if (point != null) {
            PoiSearch poiSearch = new PoiSearch(this, query);
            poiSearch.setOnPoiSearchListener(this);
            poiSearch.setBound(new PoiSearch.SearchBound(point, 5000, true));
            // 设置搜索区域为以lp点为圆心，其周围5000米范围
            poiSearch.searchPOIAsyn();// 异步搜索
        }
    }

    //TODO
    @Override
    public void onPoiSearched(PoiResult result, int rcode) {
        if (rcode == AMapException.CODE_AMAP_SUCCESS) {
            if (result != null && result.getQuery() != null) {// 搜索poi的结果
                if (result.getQuery().equals(query)) {// 是否是同一条
                    PoiResult poiResult = result;
                    //获取poi集合
                    ArrayList<PoiItem> poiItems = poiResult.getPois();
                    //结合以上addresslist.add(0, poiItem);用作显示列表,列表的第一个用作显示当前位置
                    addresslist.addAll(1, poiItems);
                    //设置列表数据
                    mLocationAddressAdapter.setNewData(addresslist);
                    List<SuggestionCity> suggestionCities = poiResult
                            .getSearchSuggestionCitys();// 当搜索不到poiitem数据时，会返回含有搜索关键字的城市信息
                }
            }
        }
    }

    @Override
    public void onPoiItemSearched(PoiItem poiItem, int i) {

    }

    @Override
    public void onRefresh() {
        doSearchQuery(mPoint);
    }

    @Override
    public void onLoadMoreRequested() {

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        String newText = s.toString().trim();
        if (AMapUtil.IsEmptyOrNullString(newText)) {
            InputtipsQuery inputquery = new InputtipsQuery(newText, city);
            Inputtips inputTips = new Inputtips(mContext, inputquery);
            inputTips.setInputtipsListener(this);
            inputTips.requestInputtipsAsyn();
        }
    }

    @Override
    public void afterTextChanged(Editable s) {
    }

    @Override
    public void onGetInputtips(List<Tip> tipList, int rCode) {
        if (rCode == AMapException.CODE_AMAP_SUCCESS) {// 正确返回
            List<String> listString = new ArrayList<String>();
            listInput = new ArrayList();
            listInput.addAll(tipList);
            for (int i = 0; i < tipList.size(); i++) {
                listString.add(tipList.get(i).getName());
            }
            ArrayAdapter<String> aAdapter = new ArrayAdapter<>(
                    getApplicationContext(),
                    R.layout.item_location_tips, listString);
            mEt_location_query.setAdapter(aAdapter);
            aAdapter.notifyDataSetChanged();
        } else {
            ShowToast.showLongToast(rCode);
        }
    }

    /**
     * 销毁定位
     *
     * @since 2.8.0
     * @author hongming.wang
     *
     */
    private void destroyLocation(){
        if (null != mlocationClient) {
            /**
             * 如果AMapLocationClient是在当前Activity实例化的，
             * 在Activity的onDestroy中一定要执行AMapLocationClient的onDestroy
             */
            mlocationClient.onDestroy();
            mlocationClient = null;
            mlocationClient = null;
        }
    }
}
